package flc.ast.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.riddle.lib.model.RiddleConst;
import com.stark.riddle.lib.model.RiddlePrefUtil;

import flc.ast.R;
import flc.ast.utils.Content;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.SPUtil;

public class SelLevelAdapter extends StkProviderMultiAdapter<Integer> {

    public SelLevelAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(66));
        addItemProvider(new SelLevelProvider());
    }

    private String levelName = "";//关卡名称，根据关卡名称获取对应关卡数
    private int page = 0;

    public void setLevelName(String levelName) {
        this.levelName = levelName;
    }

    public void setPage(int page) {
        this.page = page;
    }

    private class SelLevelProvider extends BaseItemProvider<Integer> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_level;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, Integer integer) {
            int level = 0;
            if (levelName.equals(Content.NEEDLE_LEVEL)) {
                level = SPUtil.getInt(getContext(), levelName, 1);//获取记录的关卡位置
            } else {
                level = RiddlePrefUtil.getUnlockCheckPoint(RiddleConst.FuncType.TWISTER, levelName);
            }
            int currentLevel = baseViewHolder.getPosition() + 1 + page * 24;//当前关卡数
            if (currentLevel <= level) {
                baseViewHolder.setText(R.id.tvSelLevelItemText, currentLevel + "");
                baseViewHolder.setImageResource(R.id.ivSelLevelItemImg, R.drawable.gqjx);
            } else {
                baseViewHolder.setText(R.id.tvSelLevelItemText, "");
                baseViewHolder.setImageResource(R.id.ivSelLevelItemImg, R.drawable.wjs);
            }
        }
    }
}
